package com.yc.jpyy.mobile.controller;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.base.config.Config;
import com.yc.jpyy.base.controller.BaseController;
import com.yc.jpyy.mobile.dao.BizDao;
import com.yc.jpyy.mobile.service.BizService;

@Controller
@RequestMapping(value = "/student")
public class GetDriverSchoolPhotosController extends BaseController {

	@Autowired
	private BizService bizService;

	@Autowired
	private BizDao bizDao;
	
	/**
	 * 获取前3张驾校图片
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getDriverSchoolPhotos", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String getDriverSchoolPhotos(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();

		try {
			String imgUrl = Config.getImageAddress();
			List<Map<String, Object>> listData = bizDao.getDriverSchoolPhotos(imgUrl);
			if(null!=listData && listData.size()>0){
				// 设置数据集合
				response.setData(listData);
			}else{
				response.setErrorcode(1);
				response.setMessage("无照片信息！");
			}
			
		} catch (Exception e) {
			System.out.println("获取照片信息："+ e.toString());
			response.setErrorcode(1);
			response.setMessage("获取照片信息失败!");
		} finally {
			System.out.println(response.toJSON());
			return response.toJSON();
		}

	}

}
